package com.smarthome.web.property.controller.deviceManager;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.deviceManager.EquipmentDdnsService;
import com.smarthome.domain.bean.ShEquipmentDdns;
import com.smarthome.domain.bean.ShEquipmentDevCamera;
import com.smarthome.domain.bean.ShEquipmentProducer;
import com.smarthome.domain.common.Result;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 门口机--ddns管理
 * @author shazhichao
 *
 */
@Controller
@RequestMapping("/equipmentDevDnsController")
public class EquipmentDevDnsController {

	@Resource
	private EquipmentDdnsService equipmentDdnsService;


	/**
	 * 列表
	 * 
	 * @param devcamera
	 * @param page
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(ShEquipmentDdns equipmentDdns, PageHelper page) {
		return equipmentDdnsService.getDataGrid(equipmentDdns, page);
	}

	/**
	 * 跳转到添加页面
	 * 
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest request) {
		/*request.setAttribute("info", equipmentDdnsService
				.queryShEquipmentProducerList(new ShEquipmentProducer()));*/
		return "/deviceManager/deviceDdnsAdd";
	}

	/**
	 * 新增
	 * 
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Result add(ShEquipmentDdns equipmentDdns) {
		equipmentDdnsService.add(equipmentDdns);
		return Result.success("操作成功！");
	}

	/**
	 * 跳转到编辑页面
	 * 
	 * @return
	 */
	@RequestMapping("/editPage")
	public String editPage(HttpServletRequest request, Long id) {
		request.setAttribute("ddns", equipmentDdnsService.queryEquipmentDdnsById(id));
		/*request.setAttribute("info", producerService
				.queryShEquipmentProducerList(new ShEquipmentProducer()));*/
		return "/deviceManager/deviceDdnsEdit";
	}

	@RequestMapping("/edit")
	@ResponseBody
	public Result edit(ShEquipmentDdns equipmentDdns) {
		equipmentDdnsService.edit(equipmentDdns);
		return Result.success("操作成功！");
	}
	
	
	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(Long id) {
		int num = 1;//equipmentDdnsService.delete(id);
		if (num > 0) {
			return Result.success("删除成功！");
		} else {
			return Result.failure("删除失败！");
		}
	}
}
